// JavaScript Document

var mindMapURL = "mindmapsurvey.py";

function mindmap_prefetch() {
	$.mobile.loadPage( "info.html" );		
}

function sendMindMap() {
	
	var username = USER_NAME;
	var deviceid = TEST_DEVICE;
	
	var url = urlThrive + mindMapURL;
	var args = $('#mindMap_form').serialize();
	
	// add the username and deviceid
	args = args + "&user_name=" + USER_NAME;
	args = args + "&device_id=" + TEST_DEVICE;
	args = args + "&survey_date=" + getTimeStamp();
	
	if (DEBUG_ALERTS) {
		alert(url + "?" + args);
	}
	
	removePopup();
	$.mobile.silentScroll(0);
	showPopup('&nbsp;&nbsp;Sending...&nbsp;&nbsp;');
	
	jQuery.ajax({
		timeout: 10000,
		type: "GET",
		url: url,
		data: args,
		dataType: "text",
		crossDomain: true,

		//success: function (msg) {
		success: function(data, textStatus, jqXHR){

			var message = data.split(":");
			
			if( message.length < 3) {
				$.mobile.silentScroll(0);
				removePopup();
				showPopup('Server error, please try again later.'); 
				return;
			}
			
			var success = parseInt(message[0]);
			
			if (success == 0) {
				removePopup();
				$.mobile.changePage("../../index.html");
			}
			// error!
			else if (success == -1) {
				$.mobile.silentScroll(0);
				removePopup();
				showPopup(message[1]); 
			}
		},
		error: function(jqXHR, textStatus, errorThrown){

			removePopup();
			$.mobile.changePage("../../index.html");
		}
	}); 
	
}

